import matplotlib.pyplot as plt
import numpy as np
import scipy.misc
from neuralnetwork import NeuralNetwork
import pickle
import time
import scipy

input_n = 784
hidden_n =100
output_n = 10
lr = 0.3
# 测试集合
'''with open("./model.pkl","rb") as f:
    net:NeuralNetwork = pickle.load(f)
    with open("minst_dataset\mnist_test.csv","r") as f:
        i = 0
        t = 0.0
        plt.ion() # 开启交互模式，画动图用
        plt.show()
        while True:
            i+=1
            line = f.readline() 
            if line == "":
                break
            line = np.asfarray(line.split(','))
            inputdata = line[1:]/255.0 *0.99 + 0.001 #格式化到（0，1）
            # 获取和格式化target
            target = np.zeros(output_n) + 0.001
            target[int(line[0])] = 0.99

            predict = net.forward_o(net.forward_h(inputdata)).argmax()
            ans = target.argmax()

            # img = inputdata.reshape(28,28)
            # plt.cla()
            # plt.imshow(img,cmap="grey")
            if(predict==ans):
                t+=1
            # plt.text(-10,1,f"[picture{i}]\n predict:{predict}\n{predict==ans}\n accuracy:{t/i*100}% ",color = "black")
           
            print(f"[picture{i}]\npredict:{predict}\n{predict==ans}\naccuracy:{t/i*100}% ")
            # plt.pause(0.1)

'''

# 我的手写
'''import imageio.v2 as imageio
with open("./model.pkl","rb") as f:
    net:NeuralNetwork = pickle.load(f)
    inputdata = imageio.imread("./mywrite.png")[:,:,0].flatten()
    # print(inputdata.shape)
    inputdata = np.array(inputdata/255.0 *0.99 + 0.001) #格式化到（0，1）
    # print(inputdata.shape)
    # 获取和格式化target
    predict = net.forward_o(net.forward_h(inputdata)).argmax()
    print(predict)'''
